package com.zyinhao.controller;

import com.zyinhao.dto.JsonResults;
import com.zyinhao.dto.User;
import com.zyinhao.dto.UserReqDto;
import com.zyinhao.service.ProductService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping({ "/product" })
@Api(value = "产品接口")
public class ProductController {

    @Autowired
    private ProductService productService;

    /*****  restful api：查询(GET)、增(POST)、改(PUT)、删(DELETE)    *****/
    @RequestMapping(value = "",method = RequestMethod.GET)
    @ResponseBody
    public Object find(UserReqDto dto) {
        JsonResults<Object> result = new JsonResults<Object>();

        System.out.println("####controller:ProductController:find:"+dto.toString());
        Map<String, Object> params = new HashMap<>();

        result.setData(productService.find(params));
        return result;
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Object get(@PathVariable("id") String id) {
        JsonResults<Object> result = new JsonResults<Object>();

        System.out.println("####controller:UserController:get:");
        Map<String, Object> params = new HashMap<>();

        User user = null;

        result.setData(user);
        return result;
    }

    @RequestMapping(value = "",method = RequestMethod.POST)
    @ResponseBody
    public Object add(@RequestBody User user) {
        JsonResults<Object> result = new JsonResults<Object>();
        return result;
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.PUT)
    @ResponseBody
    public Object update(@RequestBody User user, @PathVariable("id") String id) {
        JsonResults<Object> result = new JsonResults<Object>();
        return result;
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    @ResponseBody
    public Object delete(@PathVariable("id") String id) {
        JsonResults<Object> result = new JsonResults<Object>();
        return result;
    }

}